package lesson03;

import javax.swing.*;
import java.awt.*;
//图标 需要实现类，Frame继承
public class IconDemo extends JFrame implements Icon {

    private int width;
    private int heigth;

    public IconDemo(int width,int heigth){ //有参构造方法
        this.heigth=heigth;
        this.width=width; }

        public void init(){  //创建初始化方法
        IconDemo iconDemo=new IconDemo(this.width,this.heigth);
        //图标放在标签上，也可以放在按钮上
        JLabel label=new JLabel("icotest",iconDemo,SwingConstants.CENTER);
         //创建容器
         Container ct=getContentPane();
         ct.add(label);
         //显示
         this.setVisible(true);
         setBounds(200,200,500,500);
         this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) { //画图标方法
        g.fillOval(x,y,width,heigth);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.heigth;
    }

    public static void main(String[] args) {
        new IconDemo(200,50).init();
    }
}
